﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using RotovapPlatform.Domain.Equipment.Interfaces.Base;

namespace RotovapPlatform.Domain.Equipment.Device.IO
{
	/// <summary>
	/// IO信号管理器接口
	/// </summary>
	public interface IIOSignalManager
	{
		/// <summary>
		/// 获取所有DI信号
		/// </summary>
		IReadOnlyDictionary<string, IDISignal> DISignals { get; }

		/// <summary>
		/// 获取所有DO信号
		/// </summary>
		IReadOnlyDictionary<string, IDOSignal> DOSignals { get; }

		/// <summary>
		/// 获取所有AI信号
		/// </summary>
		IReadOnlyDictionary<string, IAISignal> AISignals { get; }

		/// <summary>
		/// 信号状态变化事件
		/// </summary>
		event EventHandler<IOSignalStateChangedEventArgs> SignalStateChanged;

		/// <summary>
		/// 获取DI信号
		/// </summary>
		/// <param name="id">信号ID枚举</param>
		/// <returns>DI信号对象</returns>
		IDISignal GetDISignal(DISignalId id);

		/// <summary>
		/// 获取DO信号
		/// </summary>
		/// <param name="id">信号ID枚举</param>
		/// <returns>DO信号对象</returns>
		IDOSignal GetDOSignal(DOSignalId id);

		/// <summary>
		/// 获取AI信号
		/// </summary>
		/// <param name="id">信号ID枚举</param>
		/// <returns>AI信号对象</returns>
		IAISignal GetAISignal(AISignalId id);

		/// <summary>
		/// 注册DI信号
		/// </summary>
		/// <param name="signal">DI信号对象</param>
		void RegisterDISignal(DISignal signal);

		/// <summary>
		/// 注册DO信号
		/// </summary>
		/// <param name="signal">DO信号对象</param>
		void RegisterDOSignal(DOSignal signal);

		/// <summary>
		/// 注册AI信号
		/// </summary>
		/// <param name="signal">AI信号对象</param>
		void RegisterAISignal(AISignal signal);

		/// <summary>
		/// 更新DI信号状态
		/// </summary>
		/// <param name="id">信号ID</param>
		/// <param name="state">新状态</param>
		/// <returns>更新是否成功</returns>
		bool UpdateDISignalState(DISignalId id, bool state);

		/// <summary>
		/// 批量更新DI信号状态
		/// </summary>
		/// <param name="states">位掩码表示的状态值</param>
		/// <returns>成功更新的信号数量</returns>
		int UpdateDISignalStates(int states);

		/// <summary>
		/// 批量更新DO信号状态
		/// </summary>
		/// <param name="states">位掩码表示的状态值</param>
		/// <returns>成功更新的信号数量</returns>
		int UpdateDOSignalStates(int states);

		/// <summary>
		/// 更新AI信号值
		/// </summary>
		/// <param name="id">信号ID</param>
		/// <param name="value">新值</param>
		/// <returns>更新是否成功</returns>
		bool UpdateAISignalValue(AISignalId id, double value);

		/// <summary>
		/// 设置DO信号状态
		/// </summary>
		/// <param name="id">信号ID</param>
		/// <param name="state">目标状态</param>
		/// <returns>操作是否成功</returns>
		Task<bool> SetDOSignalStateAsync(DOSignalId id, bool state);

		/// <summary>
		/// 设置多个DO信号状态
		/// </summary>
		/// <param name="signals">信号ID和状态字典</param>
		/// <returns>成功设置的信号数量</returns>
		Task<int> SetDOSignalStatesAsync(Dictionary<DOSignalId, bool> signals);
	}
}